<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
<head>
<title>viewcar.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
	function show(value,id) {
		//alert("value="+value+",id="+id);
		var xmlhttp;
		if(window.XMLHttpRequest){
			xmlhttp = new XMLHttpRequest();
		}else{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("GET","/bookshopping/servlet/UpateServlet?value="+value+"&id="+id,true);
		xmlhttp.send();
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var result = xmlhttp.responseText;// 100,500
				var sarray = result.split(",");// java中String s ="ab,cd";s.split(",")
				var itemPrice = document.getElementById(""+id);
				itemPrice.innerHTML = sarray[0];
				var carPrice = document.getElementById("carPrice");
				carPrice.innerHTML = sarray[1];
			}
		}
	}
</script>
</head>
<body>
	<form method="post" action="">
		<table width="80%" align="center" border="1px">
			<tr>
				<th colspan="7">购物车</th>
			</tr>
			<tr>
				<th>书名</th>
				<th>作者</th>
				<th>出版社</th>
				<th>单价</th>
				<th>数量</th>
				<th>总价</th>
				<th>操作</th>
			</tr>
		
			<c:forEach items="${car.items}" var="item">
				<tr align="center">
					<td>${item.book.name}</td>
					<td>${item.book.author}</td>
					<td>${item.book.publish}</td>
					<td>${item.book.price}</td>
					<td>
					<input type="text" size="1" name="updatecount" maxlength="1" value="${item.count}" onkeyup="show(this.value,${item.book.id})"/>
					</td>
					<td id="${item.book.id}">${item.totalPrice}</td>
					<td><a href="/bookshopping/servlet/DeleteCarItemServlet?id=${item.book.id}">删除</a></td>
				</tr>
			</c:forEach>
			<tr align="center">
				<td>合计:</td>
				<td colspan="6" id="carPrice">${car.total}</td>
			</tr>
			<tr align="center">
				<td colspan="7">
				<a href="${pageContext.request.contextPath}/servlet/PayServlet">结账</a>&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="/bookshopping/servlet/PageServlet?currentPage=${bp.currentPage}">继续购物</a>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
